<template>
	<view class="search-page">
		<u-navbar :autoBack="true" :placeholder="true" bgColor="#ffffff" :title="title"></u-navbar>
		<view class="shop">
			<view class="shop-item" v-for="(item,index) in list" :key="index" @click="goDetails(item.id)">
				<image :src="'https://m.lqvvvv.com'+item.avatar" mode=""></image>
				<view class="shop-right">
					<view class="name">
						{{item.title}}
					</view>
					<view class="evaluate">
						<view class="score">
							{{item.points}}
						</view>
						<view class="evaluate-text">
							{{item.service_time}}
						</view>
					</view>
					<view class="comment">
						{{item.intro}}
					</view>
					<view class="distance">
						距您直线{{item.distance}}km {{item.address}}
					</view>
					<view class="benefit">
						<view class="benefit-item" v-if="x < 3"  v-for="(i,x) in item.tags.split(',')" :key="x">
							{{i}}
						</view>
					</view>
					<view class="price"> 
						<view class="num">
							￥ <text>{{item.min_price}}</text>
						</view>
						<view>
							起
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				list: [],
				page: 1,
				status: 'loadmore',
				title: '',
				category_id: ''
			}
		},
		onLoad(e) {
			console.log(e)
			this.category_id = e.id
			this.title = e.title
			this.getList()
		},
		computed: {
			...mapState({
				location: state => state.location
			})
		},
		onReachBottom() {
			this.page = this.page + 1
			this.status = 'loading';
			this.getList()
		},
		methods: {
			goDetails(id){
				this.$navTo.togo('/pages/business/details/index',{id:id})
			},
			getList() {
				let params = {
					lat: this.location.latitude,
					lng: this.location.longitude,
					page: this.page,
					category_id: this.category_id,
					limit: 10,
				}
				console.log(params)
				this.$Request({
					method: 'POST',
					url: '/api/user_shop/getList',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						if (res.data.data.length < 10) {
							this.status = 'nomore';
						}
						if (this.page == 1) {
							this.list = res.data.data
						} else {
							this.list = [...this.list, ...res.data.data]
						}
					}
				})
			},
		}
	}
</script>
<style>
	page {
		background-color: #f8f8f8;
	}
</style>
<style scoped lang="scss">
	.search-page {
		padding: 30rpx;

		.shop {
			.shop-item {
				display: flex;
				justify-content: space-between;
				margin-bottom: 30rpx;
				background-color: #ffffff;
				padding: 20rpx;
				border-radius: 30rpx;

				image {
					width: 35%;
					height: 298rpx;
					border-radius: 30rpx;
				}

				.shop-right {
					width: 60%;
					font-size: 24rpx;

					.name {
						font-weight: bold;
						font-size: 28rpx;
						color: #000;
					}

					.evaluate {
						display: flex;
						align-items: center;
						margin-top: 10rpx;

						.score {
							background-color: #5755F2;
							padding: 5rpx 10rpx;
							border-radius: 10rpx;
							font-size: 20rpx;
							font-weight: bold;
							color: #ffffff;
							border-bottom-right-radius: 20rpx;
						}

						.evaluate-text {
							margin-left: 10rpx;
							color: #2D2D2D;
						}
					}

					.comment {
						padding: 10rpx 0;
						color: #B76CF7;
					}

					.distance {
						color: #6D6D6D;
					}

					.benefit {
						display: flex;
						margin-top: 10rpx;

						.benefit-item {
							margin-right: 20rpx;
							padding: 3rpx 7rpx;
							border: 1rpx solid #5755F2;
							border-radius: 5rpx;
							text-align: center;
							color: #5755F2;
						}
					}


					.price {
						margin-top: 10rpx;
						display: flex;
						align-items: center;
						justify-content: right;
						color: #6D6D6D;

						.cancel {
							text-decoration: line-through;
						}

						.num {
							color: #FF5959;
							display: flex;
							align-items: center;
							padding: 0 5rpx;

							text {
								font-size: 36rpx;
								font-weight: bold;
							}
						}
					}
				}
			}
		}
	}
</style>